package com.service.atf.reply.service;

import com.service.atf.base.model.Account;
import com.service.atf.base.model.TFRefund;
import com.service.atf.base.utils.ATFLogger;
import com.service.atf.reply.ac.AccountManager;
import com.service.atf.reply.core.IReadExecutor;

import java.util.Map;

/**
 * User: luotao
 * Date: 12-3-21
 * Time: 17:00:00
 */
public class RefundService implements IReadExecutor<TFRefund> {
    @Override
    public boolean isNotify() {
        return true;
    }

    public void initOut(Map out) {

    }

    @Override
    public void execute(boolean recover, AccountManager accountManager, TFRefund refund, Map out) {
        ATFLogger.sysdebug("enter refund!");
        //Validata.validataCustomerCode(this, refund.getCustomerCode());
        Account account = AccountManager.getInstance().getBussAccount(refund.getCustomerCode());
        if (account == null) {
//            CustDBService customerDBService = (CustDBService) Bootup.getAttribute(GlobalDefine.ATF_DB_KEY_CUST);
//            ATFLogger.sysdebug("��ʼ�޸���ݿ��˿�");
//            UResults uResults = customerDBService.updateCustAward(refund.getCustomerCode(), refund.getAwardTradeMoney());
//            if (!uResults.success()) {
//                String msg = "�˿�ʱ��ݿⷢ����� : custId : " + refund.getCustomerCode();
//                ATFLogger.syserr(msg);
//                throw new TFException(GlobalErrors.ATF_REFUND_DB_ERR, msg);
//            }
//            ATFLogger.sysdebug("�˿��� : " + uResults.success());
        } else {
            account.setBalcAward(account.getBalcAward() + refund.getAwardTradeMoney());
            AccountManager.getInstance().updateAccount(account);
            ATFLogger.sysdebug("account balc charge: " + account.getBalcCharge());
            ATFLogger.sysdebug("account balc award: " + account.getBalcAward());
        }

    }
}
